﻿<UserControl
    x:Class="TfsWorkbench.UIElements.PopupControls.ComboBoxTreeView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:PopupControls="clr-namespace:TfsWorkbench.UIElements.PopupControls" 
    xmlns:Interfaces="clr-namespace:TfsWorkbench.Core.Interfaces;assembly=TfsWorkbench.Core" 
    x:Name="PART_ComboBoxTreeView"
    >
    <UserControl.Resources>
    	<ResourceDictionary>
    		<ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/TfsWorkbench.UIElements;Component/Resources/ApplicationStyles.xaml"/>
    		</ResourceDictionary.MergedDictionaries>
    		<HierarchicalDataTemplate x:Key="NodeTemplate" DataType="{x:Type Interfaces:IProjectNode}" ItemsSource="{Binding Children}">
    			<TextBlock Text="{Binding Name}" />
    		</HierarchicalDataTemplate>
    	</ResourceDictionary>
    </UserControl.Resources>
    <StackPanel>
        <Popup 
            PopupAnimation="Fade"
            x:Name="PART_TreeViewPopup"
            AllowsTransparency="True"
            Placement="Bottom"
            PlacementTarget="{Binding ElementName=PART_ComboBoxTreeView}"
            Width="{Binding ActualWidth, ElementName=PART_ComboBoxTreeView}"
            MinWidth="175"
            >
            <TreeView 
                x:Name="PART_MainTreeView"
                SelectedItemChanged="OnTreeViewSelectedItemChanged"
                PreviewMouseDown="OnTreeViewMouseDown"
                KeyDown="OnTreeViewKeyDown"
                ItemTemplate="{StaticResource NodeTemplate}"
                Height="200"
                />
        </Popup>
        <ToggleButton 
			x:Name="PART_ToggleButton" 
			HorizontalContentAlignment="Stretch"
			Checked="OnShowPopup" 
			IsChecked="{Binding IsOpen, ElementName=PART_TreeViewPopup}"
			>
        	<Grid>
        		<Grid.ColumnDefinitions>
        			<ColumnDefinition />
        			<ColumnDefinition Width="16" />
        		</Grid.ColumnDefinitions>
        		<TextBlock 
        			TextTrimming="CharacterEllipsis"
        			Text="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type PopupControls:ComboBoxTreeView}}}" 
					TextAlignment="Left"
                />
				<Rectangle Margin="0" Fill="{StaticResource Arrow}" Width="8" Height="4" Grid.Column="1" />
        	</Grid>
        </ToggleButton>
    </StackPanel>
</UserControl>
